package pvp

import "github.com/hwcer/updater"

const arenaHandleUpdaterProcess = "arenaHandleUpdaterProcess"

func init() {
	updater.RegisterGlobalProcess(arenaHandleUpdaterProcess, NewArenaProcessMgr)
}

func NewArenaProcessMgr(_ *updater.Updater) any {
	return &ArenaProcessMgr{}
}

type ArenaProcessMgr struct {
	//Cycle   int64
	Battle  string //当前战斗人员
	Players []*ArenaProcessPlayer
}

type ArenaProcessPlayer struct {
	Uid   string `json:"uid"`
	Score int32  `json:"score"`
	Sort  int32  `json:"sort"`
	Flag  int8   `json:"flag"`
}

func (this ArenaProcessMgr) Get(uid string) *ArenaProcessPlayer {
	for _, v := range this.Players {
		if v.Uid == uid {
			return v
		}
	}
	return nil
}

//	func (this ArenaProcessMgr) Reset(cycle int64) {
//		if cycle != this.Cycle {
//			this.Cycle = cycle
//			this.Battle = ""
//			this.Players = []*ArenaProcessPlayer{}
//		}
//	}
func (this ArenaProcessMgr) Remaining() int32 {
	var remaining int32
	for _, v := range this.Players {
		if v.Flag == 0 {
			remaining++
		}
	}
	return remaining
}
